package com.weiqiao.mall.rest;

import com.weiqiao.mall.domain.BankEntity;
import com.weiqiao.mall.service.IBankService;
import com.weiqiao.mall.service.vo.BankVO;
import com.weiqiao.utils.PageUtil;
import com.weiqiao.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class BankController {

    @Autowired
    private IBankService bankService;

    @GetMapping("/hotbank-list")
    public ResponseEntity hotBankList(BankVO vo){

        List<BankEntity> list = bankService.hotBankList(vo);
        int total = bankService.countBank(vo);
        return new ResponseEntity(PageUtil.toPage(list,total),HttpStatus.OK);
    }

    /**
     * 获取当前银行详情
     * @param bank_id
     * @return
     */
    @GetMapping("/get-bank-info/{bank_id}")
    public ResponseEntity getBankInfo(@PathVariable String bank_id){
        int companyId = SecurityUtils.getCompanyId();
        BankEntity entity = bankService.getBankInfo(companyId, bank_id);
        return new ResponseEntity(entity, HttpStatus.OK);
    }

    @PostMapping("/update-hotbank")
    public ResponseEntity updateBank(BankVO vo){
        return new ResponseEntity(bankService.updateBank(vo),HttpStatus.OK);
    }

    @PostMapping("/insert-hotbank")
    public ResponseEntity insertBank(BankEntity vo){
        return new ResponseEntity(bankService.insertBank(vo),HttpStatus.OK);
    }

    @PostMapping("/delete-hotbank")
    public ResponseEntity deleteBank(BankVO vo){
        return new ResponseEntity(bankService.deleteBank(vo),HttpStatus.OK);
    }

    /**
     * 获取所有的热门银行
     * @return
     */
    @GetMapping("/get-bank-list")
    public ResponseEntity getBankList(){
        List<BankEntity> list = bankService.getBankList();
        return new ResponseEntity(list,HttpStatus.OK);
    }

    /**
     * 获取老系统提供的，所有的银行信息
     * @return
     */
    @GetMapping("/get-relation-bank-info")
    public ResponseEntity relationBankList(){
        return new ResponseEntity(bankService.getRelationBankInfo(),HttpStatus.OK);
    }

    /**
     * 获取老系统提供的，当前银行的卡信息
     * @return
     */
    @GetMapping("/get-relation-bank-card/{code}")
    public ResponseEntity relationBankCardList(@PathVariable String code){
        return new ResponseEntity(bankService.relationBankCardList(code),HttpStatus.OK);
    }

}
